<template>
  <div style="width: 100%">
    <a href="">下载诚信承诺书模板</a>
    <a-form :form="form" layout="horizontal" :label-col="{ span: 4 }" :wrapper-col="{ span: 14 }">
      <a-form-item label="诚信承诺书图片">
        <j-upload v-decorator="['chengxinPath', { rules: [{ required: false }] }]"></j-upload>
      </a-form-item>
      <a-form-item label="其他需上传资料">
        <j-upload v-decorator="['otherPath', { rules: [{ required: false }] }]"></j-upload>
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
import {
  Modal,
  Form,
  Input,
  DatePicker,
  Upload,
  Button,
  Icon,
  message,
  Table,
  Popconfirm,
  Divider,
} from 'ant-design-vue'
import moment from 'moment'
import { axios } from '@/utils/request'
import { tableImgMixin, tableMixin } from './mixin'

export default {
  name: 'bank9',
  mixins: [tableMixin, tableImgMixin],
  components: {
    AModal: Modal,
    AForm: Form,
    AFormItem: Form.Item,
    AInput: Input,
    ADatePicker: DatePicker,
    AUpload: Upload,
    AButton: Button,
    AIcon: Icon,
    ATable: Table,
    APopconfirm: Popconfirm,
    ADivider: Divider,
  },
  data() {
    return {
      form: this.$form.createForm(this),
      modalVisible: false,
      isEdit: false,
      currentRecord: {},
      data: [], // 这里应该是从后端获取的数据
    }
  },
  props: {
    legalCode: String,
  },
  created() {
    this.getData()
  },
  methods: {
    showAddForm() {
      this.modalVisible = true
      this.isEdit = false
      this.currentRecord = {}
      this.form.resetFields()
    },
    showEditForm(record) {
      this.modalVisible = true
      this.isEdit = true
      this.currentRecord = { ...record }
      this.$nextTick(() => {
        this.form.setFieldsValue(this.currentRecord)
      })
    },
    hideForm() {
      this.modalVisible = false
    },
    async getData() {
      try {
        const response = await this.$http.get('/register/subjectLegalAcount/list', {
          params: { legalCode: this.legalCode, pageSize: this.pagination.pageSize, pageNo: this.pagination.current },
        })
        this.data = response.result.records
        this.pagination.total = response.result.total
      } catch (error) {
        console.error('获取用户列表失败:', error)
      }
    },
    handleOk(e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          let url
          values.legalCode = this.legalCode
          if (this.isEdit) {
            values.id = this.currentRecord.id

            url = '/register/subjectLegalAcount/edit'
          } else {
            url = '/register/subjectLegalAcount/add'
          }
          const obj = values
          Object.keys(obj).forEach(k => {
            if (Array.isArray(obj[k])) {
              obj[k] = obj[k].join()
            }
          })
          axios.post(url, obj).then(r => {
            this.hideForm()
            this.getData()
          })
        }
      })
    },
    handleCancel() {
      this.hideForm()
    },
    onDelete(record) {
      axios.delete('/register/subjectLegalAcount/delete?id=' + record.id).then(r => {
        this.$message.success('删除成功')
        this.getData()
      })
    },
  },
}
</script>

<style scoped>
/* 可以在这里添加样式 */
</style>
